Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use ephemeral storage when storage would otherwise be blocked #7207

Closed
wants to merge 3 commits into from

Conversation

cathiechen
Copy link

@cathiechen cathiechen commented Nov 20, 2020

Resolves brave/brave-browser#12789

Submitter Checklist:

  • There is a ticket for my issue.
  • Used Github auto-closing keywords in the commit message.
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed).
  • Requested a security/privacy review as needed.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@cathiechen cathiechen requested a review from a team as a code owner November 20, 2020 08:01
@mrobinson mrobinson marked this pull request as draft December 9, 2020 11:45
@mrobinson mrobinson changed the title Ephemeral dom storage flag Only use ephemeral storage when storage would otherwise be blocked Dec 9, 2020
@mrobinson
Copy link
Contributor

This PR will need to be rebased and also include support for network cookies and document.cookie.

Instead of using ephemeral storage for all unblocked third-party frame
storage, only use ephemeral storage when third-party storage is blocked.
This means that turning on the ephemeral storage flag will always
replaced blocked storage in third-party frames with an ephemeral
version, regardless of other settings.
@cathiechen cathiechen marked this pull request as ready for review December 18, 2020 17:18
@cathiechen
Copy link
Author

Hi @bridiver @iefremov @mrobinson, I think this patch is ready to review now.
Sorry, somehow I'm not able to add reviewers to this PR.

@mrobinson mrobinson self-requested a review December 18, 2020 17:24

#define BRAVE_STORAGE_CONTROLLER_H \
public: \
static bool CanAccessStorageAreaWithoutEphemeralStorage( \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a static method on StorageController? I can't see any reason for it to be part of StorageController and seems like it would work just as well as an anonymous method added to dom_window_storage.cc

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, IIUC, CanAccessStorageAreaWithoutEphemeralStorage replaces the original CanAccessStorageArea in storage_controller.h. And the current CanAccessStorageArea returns true if cookie allowed or ephemeral flag enabled.
It seems we can't move this to dom_window_storage.cc, for the StorageArea::CanAccessStorage() needs it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then it can just be a regular method and not a static method on a class that requires a patch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this change has been removed in the new patch.

return task_runner_;
}

+ BRAVE_STORAGE_CONTROLLER_H
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
};

IN_PROC_BROWSER_TEST_F(EphemeralStorageDisabledBrowserTest,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have two tests with the same name ThirdPartyCookiesEnabled

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are distinguished by the test class names (EphemeralStorageBrowserTest and EphemeralStorageDisabledBrowserTest). So do you prefer to point out the ephemeral flag values explicitly in the test names?

EXPECT_EQ("from=b.com", site_a_tab_values.iframe_2.cookies);
}

IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what "NavigateCookies" is supposed to mean here or "Enabled". Does "Enabled" mean the setting is enabled or that third party cookies are allowed? Using "Blocked" or "Allowed" I think is more useful here. Also it's helpful if you describe the behavior like "UseEphemeralStorageWhenThirdPartyCookiesAreBlocked"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks

return task_runner_;
}

+ BRAVE_STORAGE_CONTROLLER_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bridiver suggested that this might be able to be removed entirely by just moving CanAccessStorageAreaWithoutEphemeralStorage into chromium_src/third_party/blink/renderer/modules/storage/dom_window_storage.cc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EXPECT_EQ("from=b.com", site_a_tab_values.iframe_2.cookies);
}

IN_PROC_BROWSER_TEST_F(EphemeralStorageDisabledBrowserTest,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also looks like a duplicate test name

@@ -554,3 +584,212 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest,
EXPECT_EQ("third-party-a.com", third_party_values.session_storage);
EXPECT_EQ("name=third-party-a.com", third_party_values.cookies);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to test shield and chromium site overrides for block all and block 3p based on the discussion we had with @pes10k about that behavior

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also you don't have any tests for BlockAll and I'm fairly certain they won't work correctly with these changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So all storage should not be accessible when BlockAll cookies, no matter ephemeral flags on or off?
OK, will do.


bool can_get_cookies =
(request_info_.privacy_mode == PRIVACY_MODE_DISABLED && CanGetCookies());
+ BRAVE_SETCOOKIEHEADERANDSTART
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this patch can probably be eliminated by changing the subclass of URLRequestHttpJob and overriding CanGetCookies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CanGetCookies probably cannot be overridden since it isn't virtual, but I guess it's possible to create a new version of this function or a new method, perhaps with the preprocessor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that putting this in url_request_http_job.cc is sufficient to remove the patch.

+#define CanGetCookies() \
+  (CanGetCookies() || CanUseEphemeralStorage(this))
+

Then, of course, #undef CanGetCookies at the end of the file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrobinson that would also work, but I think you still have the problem discussed in slack of differentiating between block 3p and block all

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrobinson that is a good idea though and I think we can still use it per the dm discussion with || true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@cathiechen
Copy link
Author

Hi,
I think this patch is ready for review.
The latest commit makes all the accessible checking relying on the interfaces in CookieSettingsBase which support block all cookies setting. But this seems to lead to more changes for providing the interfaces.

PTAL, thanks!

@cathiechen
Copy link
Author

Hi,
Let me explain the new patch a bit.
This patch provides two access interfaces for dom storage, navigated cookie and js cookie to check if the storage is accessible for an url and which kind of storge it should use.
All the interfaces will eventually call CookieSettingsBase which provides IsCookieAccessOrEphemeralCookiesAccessAllowed (It contains the ephemeral settings and cookie settings. And returns false if cookie settings is block_all. It determines whether an url is accessible to storage) and IsCookieAccessAllowed (Only contains cookie settings. It determines which storage should be used, normal storage or ephemeral storage).
To use the interfaces in cookie_settings_base.h, we need to add extra interfaces for each storage services.

  • Dom storage: In order to use the interfaces in DOMWindowStorage, we need to add interfaces in WebContentSettingsClient, BraveContentSettingsAgentImpl, content_settings_manager.mojom, and ContentSettingsManagerImpl. Then they eventually call interfaces in CookieSettingsBase.
  • The navigated cookies: To use them in URLRequestHttpJob, we need to add interfaces in NetworkDelegate, NetworkServiceNetworkDelegate which calls interfaces in CookieSettingsBase.
  • The js cookies: It changes RestrictedCookieManager.

@bridiver
Copy link
Collaborator

closed in favor of #7647

@bridiver bridiver closed this Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ephemeral storage should work when third-party cookies are blocked
3 participants